<%--
  Created by IntelliJ IDEA.
  User: 诸葛龙辰
  Date: 2023/3/3
  Time: 20:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加</title>
    <script type="text/javascript" src="/js/jquery-3.4.1.min.js"></script>
</head>
<body>
<h2 align="center">添加</h2>
<div id="error" ></div>
<form id="addFrm">
    <table border="1" width="600px" align="center">
        <tr >
            <td>员工名称：</td>
            <td><input type="text" name="empName" id="empName"></td>
        </tr>
        <tr >
            <td>年：</td>
            <td><input type="text" name="year" id="year"></td>
        </tr>
        <tr>
            <td>月：</td>
            <td><input type="text" name="month" id="month"></td>
        </tr>
        <tr>
            <td>工资：</td>
            <td><input type="text" name="salary" id="salary"></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="button" id="btn" value="添加"></td>
        </tr>
    </table>
</form>
<script>
    $(function (){
        $("#btn").click(function (){
            var emp = $("#addFrm").serialize();
            $.ajax({
                url:"/EmpServlet/add1",
                type:"get",//请求的方法
                data:emp,
                contentType:"json",
                success:function (data){
                    if (data>0){
                        location.href = "/emp/list1.jsp";
                    }else{
                        $("#error").html("添加失败！！")
                    }
                },
                error: function(data){
                    alert("添加失败")
                }
            });
        })
    })
</script>
</body>
</html>
